package com.lib.framework.receiver

import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import com.lib.framework.base.BaseBroadcastReceiver
import com.lib.framework.manager.thread.bgThreadRun
import com.lib.framework.utils.AppUtil


/**
 * 飞行模式 广播接收器
 * @author keanbin
 */
abstract class AAirPlaneModeBroadcastReceiver(context: Context) : BaseBroadcastReceiver(context) {

    override fun getIntentFilter(): IntentFilter {
        val intentFilter = IntentFilter()
        intentFilter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED)
        return intentFilter
    }

    override fun onReceive(context: Context?, intent: Intent?) {
        if (intent == null) return

        when (intent.action) {
            Intent.ACTION_AIRPLANE_MODE_CHANGED -> {
                bgThreadRun {
                    onAirPlaneModeChange(AppUtil.isAirModeOn(mContext))
                }
            }
        }
    }

    /**
     * 飞行模式 发生改变
     */
    abstract fun onAirPlaneModeChange(isAirModeOn: Boolean)
}